<!--
 * Copyright ©
 * #  
 * @author: zw
 * @date: 2022-01-07 
 -->

<template>
  <el-skeleton :loading="loading" animated :throttle="500" :count="4">
    <template #template>
      <div class="ske-item">
        <el-skeleton-item class="ske-main" variant="h2" />
      </div>
    </template>
    <template #default>
      <el-row class="wrapper" :gutter="20">
        <el-col :span="6" v-for="item in top_list" :key="item.id" class="toplist_item">
          <div class="coverImg">
            <el-image :src="item.coverImgUrl"></el-image>
          </div>
          <div class="toplist_wrapper">
            <h4 class="toplist_hd">{{ item.name }}</h4>
            <div class="toplist_songlist">
              <div class="songitem" v-for="(songItem, index) in songList[item.id]" :key="songItem.id">
                <div class="songnum">{{ index + 1 }}</div>
                <div class="songinfo">
                  <router-link :to="{ path: '/song', query: { id: songItem.id } }" class="song_title">
                    {{ songItem.name }}</router-link>
                  <div class="song_author">
                    <router-link :to="{ path: '/singer', query: { id: author.id } }" class="song_name" v-for="(author, k) in songItem.ar" :key="k">
                      {{ k !== 0 ? "/ " + author.name : author.name }}
                    </router-link>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
    </template>
  </el-skeleton>
</template>

<script>
import { defineComponent, onMounted, reactive, toRefs } from "vue";
import { useInstance } from "@/hooks";
import { TOPLIST, TOPRANKLIST } from "@/api";
export default defineComponent({
  name: "RankList",
  setup(props, { emit, slots }) {
    const { $Message: $message } = useInstance();
    const info = reactive({
      top_list: [],
      songList: {},
      loading: true,
    });

    const getToplist = async () => {
      const { code, list } = await TOPLIST();
      if (code !== 200) return $message.error("数据请求失败");
      info["top_list"] = list.splice(0, 4);
      info["top_list"].forEach(async (item, index) => {
        const { playlist } = await TOPRANKLIST({ id: item.id });
        info["songList"][item.id] = playlist.tracks.splice(0, 6);
      });

      info["loading"] = false;
    };
    onMounted(() => {
      getToplist();
    });
    return {
      ...toRefs(info),
    };
  },
});
</script>
<style lang="scss" scoped>
.toplist_item {
  position: relative;
  margin-bottom: 30px;

  .coverImg {
    position: absolute;
    top: 0;
    right: 10px;
    left: 10px;
    z-index: 1;
    height: 100%;

    &::before {
      position: absolute;
      top: 0;
      left: 0;
      z-index: 2;
      content: "";
      width: 100%;
      height: 100%;
    }

    :deep(img) {
      filter: blur(60px);
      transform: scale(1.5);
    }
  }

  .toplist_wrapper {
    position: relative;
    z-index: 2;
  }

  &:hover {
    :deep(img) {
      transform: scale(2);
    }
  }
}

.toplist_wrapper {
  padding: 30px 40px;
  height: 505px;

  .toplist_hd {
    position: relative;
    font-size: 24px;
    text-align: center;
    color: #fff;

    &::after {
      display: inline-block;
      content: "";
      position: absolute;
      bottom: -30px;
      left: 0;
      right: 0;
      width: 30px;
      height: 2px;
      margin: 0 auto;
      background-color: #fff;
    }
  }

  .toplist_songlist {
    padding-top: 80px;
  }

  .songitem {
    display: flex;
    padding-bottom: 20px;
    color: #fff;

    .songnum {
      padding-right: 10px;
      font-size: 18px;
    }

    .song_title {
      line-height: 24px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      -webkit-box-orient: vertical;
      word-break: break-all;
      padding-bottom: 5px;
      font-size: 14px;
      color: #fff;
      transition: all 0.3s ease-in;
    }

    .song_author {
      display: block;
      font-size: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      -webkit-box-orient: vertical;
      word-break: break-all;

      a {
        display: inline-block;
        line-height: 20px;
        font-size: 14px;
        color: #fff;
      }
    }

    &:hover {
      .song_title {
        transform: translate(15px, 0);
        transition: all 0.3s ease-in;
      }
    }

    &:last-child {
      padding-bottom: 0;
    }
  }
}

.el-skeleton {
  width: auto;
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  margin: 0 -10px;
  box-sizing: border-box;

  .ske-item {
    flex: 1;
    width: 25%;
    margin: 0 10px;
  }

  .ske-main {
    height: 505px;
  }
}
</style>
